*********************************************************************************
/* Deterrence Effect plus Initial Audit Revenue over Marginal Costs, by Income		*/
*********************************************************************************
* Set directories 

* File paths
local datapath "${mvpf_audits}/data/cleaned" 
local datafolder "${mvpf_audits}/data/outside" 
local graphpath "${graphpath}" 

* Version of fig to produce 
global version  ${version} // paper or slides

* Other formatting
if "${version}" == "slides" {
	global title "title(" ", size(vhuge))"
	global img wmf
	graph set window fontface "Arial"
	global title "title(" ", size(vhuge))"
	global axis_size "" //xsize(6.5) ysize(4)" // makes figure wider
}

else if "${version}" == "paper" {
	global title "title("")"
	global img pdf
	graph set window fontface "LMRoman10-Regular"
	global title " "
	global axis_size " " // makes figure wider
}

/*------------------------------------------------------------------------------
Plot with paper formatting
------------------------------------------------------------------------------*/

local spec = `" " " "_l" "_h""'
use "${mvpf_audits}/data/figures_rep/figure_7.dta", clear

if "${version}" == "paper" {
	* marginal R/C including deterrence effects - excluding top 1%
	twoway  (scatter rc_marginal_det_const xaxis if inrange(xaxis, 1, 10), mc("${rc_col}") ms(S)) ///
		(rcap rc_marginal_det_const_h rc_marginal_det_const_l xaxis if inrange(xaxis, 1, 10), lc("${rc_col}")) ///
		, ///
		yline(0, lw(thin) lp(solid) lc(gs11)) ///
		xtitle("TPI Decile") ytitle("Audit Revenue + Deterrence / Marginal Cost") ///
		xlabel(1(1)10 , valuelabel  nogrid) xscale(r(1 10)) ///
		ylab(, nogrid) ///
		legend(off) ///
		${title} ${axis_size}					
graph export "`graphpath'/coeffplot_marginal_rc_deterrence_tpi.wmf", as(wmf) replace	
	
* cap y-axis
preserve
foreach s of local spec{
	replace rc_marginal_det`s' = -6 if rc_marginal_det`s'<=-6
	replace rc_marginal_det`s' = 48 if rc_marginal_det`s'>=48 & ~missing(rc_marginal_det`s')
	
	replace rc_marginal_det_const`s' = -6 if rc_marginal_det_const`s'<=-6
	replace rc_marginal_det_const`s' = 48 if rc_marginal_det_const`s'>=48 & ~missing(rc_marginal_det_const`s')
} 

* marginal R/C including detrrence effects
twoway  (scatter rc_marginal_det_const xaxis, mc("${rc_col}") ms(S)) ///
		(rcap rc_marginal_det_const_h rc_marginal_det_const_l xaxis, lc("${rc_col}")) ///
		(scatter rc_marginal_det xaxis2, mc("${rc_col}*0.5") ms(S)) ///
		(rcap rc_marginal_det_h rc_marginal_det_l xaxis2, lc("${rc_col}*0.5")) ///
		, ///
		yline(0, lw(thin) lp(solid) lc(gs11)) ///
		xtitle("TPI Decile") ytitle("Audit Revenue + Deterrence / Marginal Cost") ///
		xlabel(1(1)12 , valuelabel  nogrid) xscale(r(0.7 12.3)) ///
		ylab(-6 "<-6" 0 "0" 6 "6" 12 "12" 18 "18" 24 "24" 30 "30" 36 "36" 42 "42" 48 "48+", nogrid) ///
		legend(ring(0) pos(11) row(2) symxsize(*0.3) order(1 3) ///
			lab(1 "Constant deterrence multiplier of 3.2x") lab(3 "TPI-specific multipliers")) ///
		${title} ${axis_size}	
graph export "`graphpath'/coeffplot_marginal_rc_deterrence_tpi_appendix.wmf", as(wmf) replace
restore
}

/*------------------------------------------------------------------------------
Plot with slide formatting
------------------------------------------------------------------------------*/
if "${version}" == "slides" {
	* marginal R/C including deterrence effects - excluding top 1%
	twoway  (scatter rc_marginal_det_const xaxis if inrange(xaxis, 1, 10), mc("${rc_col}") ms(S)) ///
		(rcap rc_marginal_det_const_h rc_marginal_det_const_l xaxis if inrange(xaxis, 1, 10), lc("${rc_col}")) ///
		///(scatter rc_marginal_det xaxis2, mc("${rc_col}*0.5") ms(S)) ///
		///(rcap rc_marginal_det_h rc_marginal_det_l xaxis2, lc("${rc_col}*0.5")) ///
		, ///
		text(`rc_90' 9.6 "`rc_90'", size(2.75))  ///
		text(`rc_70' 7.6 "`rc_70'", size(2.75))  ///
		text(`rc_20' 2.6 "`rc_20'", size(2.75))  ///
		yline(0, lw(thin) lp(solid) lc(gs11)) ///
		xtitle("TPI Decile") ytitle("Audit Revenue + Deterrence / Marginal Cost") ///
		xlabel(1(1)12 , valuelabel labsize(3.5) nogrid) xscale(r(0.5 12.5)) ///
		ylab(, nogrid) ///
		legend(off) ///
		${title} ${axis_size}					
graph export "`graphpath'/coeffplot_marginal_rc_deterrence_tpi.wmf", as(wmf) replace
	
	* marginal R/C including deterrence effects - excluding top 1%
	twoway  (scatter rc_marginal_det_const xaxis if inrange(xaxis, 1, 10), mc("${rc_col}") ms(S)) ///
		(rcap rc_marginal_det_const_h rc_marginal_det_const_l xaxis if inrange(xaxis, 1, 10), lc("${rc_col}")) ///
		, ///
		text(`rc_90' 9.6 "`rc_90'", size(2.75))  ///
		text(`rc_70' 7.6 "`rc_70'", size(2.75))  ///
		text(`rc_20' 2.6 "`rc_20'", size(2.75))  ///
		yline(0, lw(thin) lp(solid) lc(gs11)) ///
		xtitle("TPI Decile") ytitle("Audit Revenue + Deterrence / Marginal Cost") ///
		xlabel(1(1)12 , valuelabel labsize(3.5) nogrid) xscale(r(0.5 12.5)) ///
		ylab(0(4)28, nogrid) ///
		legend(off) ///
		${title} ${axis_size}					
graph export "`graphpath'/coeffplot_marginal_rc_deterrence_tpi.wmf", as(wmf) replace

* cap y-axis
preserve

foreach s of local spec{
	replace rc_marginal_det`s' = 0 if rc_marginal_det`s'<=0
	replace rc_marginal_det`s' = 28 if rc_marginal_det`s'>=28 & ~missing(rc_marginal_det`s')
	
	replace rc_marginal_det_const`s' = 0 if rc_marginal_det_const`s'<=0
	replace rc_marginal_det_const`s' = 28 if rc_marginal_det_const`s'>=28 & ~missing(rc_marginal_det_const`s')
} 

* marginal R/C including detrrence effects
twoway  (scatter rc_marginal_det_const xaxis, mc("${rc_col}") ms(S)) ///
		(rcap rc_marginal_det_const_h rc_marginal_det_const_l xaxis, lc("${rc_col}")) ///
		(scatter rc_marginal_det xaxis2, mc("${rc_col}*0.5") ms(S)) ///
		(rcap rc_marginal_det_h rc_marginal_det_l xaxis2, lc("${rc_col}*0.5")) ///
		, ///
		yline(0, lw(thin) lp(solid) lc(gs11)) ///
		xtitle("TPI Decile") ytitle("Audit Revenue + Deterrence / Marginal Cost") ///
		xlabel(1(1)12 , valuelabel labsize(3.5)  nogrid) xscale(r(0.5 12.5)) ///
		ylab(0(4)28, nogrid) ////
		/// legend(off) ///
		legend(ring(0) pos(11) row(2) symxsize(*0.3) order(1 3) ///
		lab(1 "Constant deterrence multiplier of 3.2X") lab(3 "TPI-specific multipliers")) ///
		${title} ${axis_size}	
graph export "`graphpath'/coeffplot_marginal_rc_deterrence_tpi_appendix.wmf", as(wmf) replace
restore
}
